package com.taxicall.client;

import java.util.ArrayList;
import java.util.List;

import com.taxicall.entities.NetworkMessage;
import com.taxicall.entities.TaxiLocation;
import com.taxicall.entities.NetworkMessage.MessageType;

import android.os.Bundle;
import android.os.ResultReceiver;
import android.app.Activity;
import android.widget.Button;
import android.widget.EditText;
import android.view.View;
import android.content.Intent;

public class ClientIntro extends Activity {
	private static ArrayList<TaxiLocation> points;
	private ResultReceiver resReceiver;
	private Intent serviceIntent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_client_intro);
		
		final EditText serverip = (EditText) findViewById(R.id.serverip);
		
		NetworkMessage msgToSend = new NetworkMessage(MessageType.GetStartLocations, "");
		
		System.out.println("before service call");
		resReceiver = new MyResultReceiver(null);
		serviceIntent = new Intent(this, UDPService.class);
		serviceIntent.putExtra("resultReceiver", resReceiver);
		serviceIntent.putExtra("msg", msgToSend);
		serviceIntent.putExtra("serverip", serverip.getText().toString());
		startService(serviceIntent);
		System.out.println("after service call");
		
		Button introBut = (Button) findViewById(R.id.introBut);
		
		introBut.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent nextActivity = new Intent(getApplicationContext(), StartPointSelection.class);
				nextActivity.putExtra("TaxiLocations", points);
				nextActivity.putExtra("serverip", serverip.getText().toString());
				startActivity(nextActivity);
			}
		});
	}
	
	protected void onDestroy() {
		super.onDestroy();
		stopService(serviceIntent);
	}
	
	public static void getTaxiLocations(List<TaxiLocation> list) {
		points = new ArrayList<TaxiLocation>(list);
	}
}
